<?php
//Ten file muon xuat ra de in

$v_recordtype_filter = $_SESSION['onegate_current_recordtype'];
if(isset($_REQUEST['hdn_recordtype_filter'])){
	$v_recordtype_filter = $_REQUEST['hdn_recordtype_filter'];
} 
$v_file_name = "noi_dung_giay_phep.htm";
$v_xml_str = $arr_single_record['C_LICENSE_XML_DATA'];

//file chua cac the can thay the
$v_receipt_xml_file = "../../xml/".$v_recordtype_filter."/mau_in_giay_phep.xml";
//
if (file_exists($v_receipt_xml_file)){
	$v_receipt_xml_string = _read_file($v_receipt_xml_file);
}else{
	echo "<Center><B>H&#7878; TH&#7888;NG KH&#212;NG T&#204;M TH&#7844;Y M&#7850;U V&#258;N B&#7842;N TR&#7842; K&#7870;T QU&#7842; C&#7846;N IN</B></Center>";
}
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_receipt_xml_string);
$table_struct_rax->record_delim = 'application_form';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
//lay ten file
$v_file_name = $table_struct_row["file_name"];
$v_file_name_changle = $table_struct_row["file_name_changle"];
//kiem tra xem la dkkd ho ca the hay dkkd hop tac xa?
//001: DKKD ho ca the; 002: DKKD hop tac xa
if(($v_recordtype_filter == "002") || ($v_recordtype_filter == "001")){
	$struct_rax = new RAX(); 
	$struct_rec = new RAX(); 
	$struct_rax->open($v_xml_str);
	$struct_rax->record_delim = "data_list";
	$struct_rax->parse();
	$struct_rec = $struct_rax->readRecord(); 
	while ($struct_rec){ 
		$struct_rec_row = $struct_rec->getRow();
		$v_form_record = $struct_rec_row["record_form"];
		//luu so dang ky kinh doanh
		$v_record_number = $struct_rec_row["record_number"];		
		$struct_rec = $struct_rax->readRecord();
	}	
	if(!is_null($v_form_record) && ($v_form_record<>"")){
		if(($v_form_record<>"DKLD")){
			session_start();
			$_SESSION['v_recordtype_filter_code'] = $v_recordtype_filter;		
			$v_file_name = $v_file_name_changle;
		}
	}
}
//echo $arr_single_record['C_LICENSE_XML_DATA'];exit;
if($v_recordtype_filter=="009")
{
	if(_XML_get_xml_tag_value($arr_single_record['C_LICENSE_XML_DATA'],"record_form","record_form")=="CGP_XDT")
	{
		$v_file_name = "mau_giay_phep_cpxd_tam.htm";
	}
	else{
			if(_XML_get_xml_tag_value($arr_single_record['C_LICENSE_XML_DATA'],"chu_dau_tu","chu_dau_tu")==''&& 
				_XML_get_xml_tag_value($arr_single_record['C_LICENSE_XML_DATA'],"kv_nui","kv_nui")=='')
			{
				$v_file_name = "mau_giay_phep_cpxd3.htm";
			}
			else if(_XML_get_xml_tag_value($arr_single_record['C_LICENSE_XML_DATA'],"kv_nui","kv_nui")=='') 
			{
				$v_file_name = "mau_giay_phep_cpxd1.htm";
			}
			else if(_XML_get_xml_tag_value($arr_single_record['C_LICENSE_XML_DATA'],"chu_dau_tu","chu_dau_tu")=='')
			{
				$v_file_name = "mau_giay_phep_cpxd2.htm";
			}
			else {
				$v_file_name = "mau_giay_phep_cpxd.htm";
			}
	}
}

//doan ma nay lay len 2 dong dang kya lan dau va dang ky thay doi hoac cap lai khi in giay phep
if($v_recordtype_filter=="048" && _XML_get_xml_tag_value($arr_single_record['C_LICENSE_XML_DATA'],"record_form","record_form")=="DKLD") {

		$v_file_name = "mau_giay_phep_dktdnd_dkkdtndkdd_cdhdkd_048.htm";

}

//echo 'v_recordtype_filter' . $v_recordtype_filter;exit;
$v_receipt_richtext_file = "../../template/" . $v_recordtype_filter . "/" . $v_file_name;
//echo $v_receipt_richtext_file; exit;
if(!file_exists($v_receipt_richtext_file)){
	$v_receipt_richtext_file = "../../template/" . $v_file_name;
}
$v_receipt_richtext_string = _read_file($v_receipt_richtext_file);

//$v_receipt_richtext_string = str_replace("#RECORD_DATE_FIRST_REGISTER#",$arr_single_record_date['NgayDangKy'],$v_receipt_richtext_string);
/*if($v_recordtype_filter=="009" && _XML_get_xml_tag_value($arr_single_record['C_LICENSE_XML_DATA'],"record_form","record_form")=="CGP_XDT"){
if(_XML_get_xml_tag_value($arr_single_record['C_LICENSE_XML_DATA'],"building_area_total","building_area_total")!='')
	{
		//echo $v_receipt_richtext_string;exit;
	 	$v_receipt_richtext_string = str_replace('#TOTAL_AREA#','T&#7893;ng di&#7879;n t&iacute;ch s&agrave;n: #TOTAL_AREA# m<sup>2</sup>.',$v_receipt_richtext_string);

	}
}	*/
echo $v_richtext_output = Print_Receipt_From_XML($v_receipt_xml_string,$v_receipt_richtext_string,$v_xml_str,$arr_single_record);


//echo $v_xml_str.'<br>';
//var_dump($arr_single_record);

//_write_file($v_file_name,$v_richtext_output);
?>